<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>定时器示例</title>
</head>
<body>

<input type="text" id="result" id="text">

<input type="button" value="开始"  id="btn1">
<input type="button" value="结束" id="btn2" >

<script type="text/javascript">
    var time = 0;
    var seconde=0;
    var btn1 = document.getElementById("btn1");
    var btn2 = document.getElementById("btn2");
    var text = document.getElementById("text");
    function getStyle(elem, prop) {
        if (window.getComputedStyle) {
            return window.getComputedStyle(elem, null)[prop];
        } else {
            return elem.currentStyle[prop];
        }
    }
    var count = 1;//设置时间戳
    btn1.addEventListener("click",showTime)
    function showTime(e) {
        if(count){
            time = setInterval(function () {
                seconde++;
                text.value = seconde;
            }, 1000)
            count =0;
        }
    }
    btn2.addEventListener("click",stopTime)
    function stopTime(){
        clearInterval(time);
        count =1;
    }
</script>
</body>
</html>